package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import org.junit.Test;

/**
 * Label标签的练习
 */
public class Main3 extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Scene scene = new Scene(new Group());
        stage.setTitle("Label Sample");
        stage.setWidth(400);
        stage.setHeight(180);


        HBox hbox = new HBox();

        Label label1 = new Label("Search long long long long long long long long long ");
        label1.setPrefWidth(300);
        label1.setTextFill(Color.rgb(255, 122, 144));
        //将包装文本适合布局区域
        //label1.setWrapText(true);

        //旋转Label标签
        //label1.setRotate(100);

        //移动标签
        //label1.setTranslateY(50);

        //添加缩放事件
        //当鼠标移入时放大至原来的的1.5倍
        label1.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                //设置缩放倍数
                label1.setScaleX(1.5);
                label1.setScaleY(1.5);
            }
        });
        //当鼠标移出时还原来的倍数
        label1.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                label1.setScaleX(1);
                label1.setScaleY(1);
            }
        });

        Button btn = new Button("点击切换");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                label1.setText("点击了");
            }
        });

        hbox.setSpacing(10);
        hbox.getChildren().addAll(label1,btn);

        ((Group) scene.getRoot()).getChildren().add(hbox);

        stage.setScene(scene);
        stage.show();

    }
}
